/**
 * 
 */
package com.effectivsocial.email;

import java.util.Locale;


import jodd.util.StringUtil;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

/**
 * @author Dhrubo
 *
 */
public class EmailBodyPreparer<T> {
	
	
	private T entity;
	private String templateName;
	private Locale locale;
	
	public EmailBodyPreparer(T entity,String templateName, Locale locale){
		this.entity = entity;
		this.templateName = templateName;
		this.locale = locale;
	}
	
	public String prepareFromTemplate(TemplateEngine templateEngine){
		final Context context = new Context(locale);
		context.setVariable(StringUtil.decapitalize(entity.getClass().getSimpleName()), entity);
		return templateEngine.process(templateName, context);
	}
}
